package com.ycw.servlet.laowei;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.ycw.dao.HouseDao;
import com.ycw.dao.impl.HouseDaoImpl;
import com.ycw.pojo.House;

/**
 * Servlet implementation class Addhouse
 */
@WebServlet("/Addhouse")
public class HouseAddServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public HouseAddServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 添加房屋信息
		HouseDao hDao = new HouseDaoImpl();

		House house = new House(0, request.getParameter("hregion"), request.getParameter("hvillage"),
				request.getParameter("hunit"), request.getParameter("hroomnum"), request.getParameter("horientation"),
				request.getParameter("hrenovation"), Integer.parseInt(request.getParameter("hshuangqi")),
				request.getParameter("hfacilities"), Integer.parseInt(request.getParameter("hprice")),
				Integer.parseInt(request.getParameter("hstate")), request.getParameter("hpic"),
				request.getParameter("haddtime"));
		int i = hDao.addHouseInfo(house);
		boolean f = false;
		if (i > 0) {
			f = true;
		}
		// 向前端发送JSON数据
		String resJSON = JSON.toJSONString(f);
		PrintWriter out = response.getWriter();
		out.write(resJSON);
		out.close();
	}

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		super.destroy();
	}

	@Override
	public void init() throws ServletException {
		// TODO Auto-generated method stub
		super.init();
	}

}
